Repository navigation
fix(submission): accept a linear scale answer only as its plain number - #3977
Merged
Merged
Conversation
1 task done
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
AndyScherzinger
force-pushed
the
fix/scale-answer-plain-number
branch
from
November 21, 2026 16:14
fe4519f to
fa31015
Compare
This was referenced Nov 21, 2026
AndyScherzinger
commented
Nov 21, 2026
AndyScherzinger
force-pushed
the
fix/scale-answer-plain-number
branch
from
November 21, 2026 19:44
fa31015 to
eb66419
Compare
AndyScherzinger
commented
Nov 21, 2026
AndyScherzinger
commented
Nov 21, 2026
AndyScherzinger
commented
Nov 21, 2026
AndyScherzinger
commented
Nov 21, 2026
AndyScherzinger
commented
Nov 21, 2026
Chartman123
approved these changes
Nov 21, 2026
The check of a linear scale answer accepted "05" and the JSON number 4.0, as ctype_digit() only looked at the digits of the value cast to a string. "05" was stored as sent, so the results counted it as a value of its own next to "5", and exports showed it as written. 4.0 was stored as "4". The check now reads the answer with normalizeNumericOptionId(), so a linear scale answer follows the same plain-number rule as the option ids of choice questions: a number, or a string of exactly its digits. For API clients that send "05" or 4.0 this changes behaviour: they get an error that names the rule. Answers already stored are not affected. The submit page restores a scale answer from a draft or from an edited response as its plain number as well, so an answer stored as "05" before is sent back as "5" instead of being rejected. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
AndyScherzinger
force-pushed
the
fix/scale-answer-plain-number
branch
from
November 21, 2026 21:25
eb66419 to
3b2e625
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack
Part 1 of 3 of the linear scale stack. Merge in this order:
This PR targets
main. #3978 builds on it, so it merges first.Screenshots (stacked PR)
A linear scale answer passed the server's check when it was written with leading zeros (
"05") or as a JSON number with a fraction part (4.0), because the check only looked at the digits of the value cast to a string."05"was stored as sent: the results summary then counted it as a value of its own next to5, and exports showed it as written.4.0was stored as"4".The check now reads the answer with
normalizeNumericOptionId(), the helper that already reads option ids of choice questions, so a linear scale answer follows the same plain-number rule: a number, or a string of exactly its digits. Valid answers (3,"3","0"on a 0-based scale) are accepted as before, and booleans and lists are still rejected. For API clients that send"05"or4.0this changes behaviour: they now get a 400 that names the rule. Answers already stored are not affected.docs/API_v3.mdnow describes the accepted form of a linear scale answer.The submit page restores a linear scale answer from a draft or from an edited response as its plain number as well (
withOfferedValues()inSubmit.vue), so a response stored with"05"before this change can still be edited and saved instead of being rejected.Split out of #3637, where it was found while reviewing the rating question, which now builds on the linear scale.
How to verify
Submit
{"answers": {"<scale question id>": ["05"]}}to a form with a linear scale (POST /ocs/v2.php/apps/forms/api/v3/forms/{formId}/submissions): it is now rejected with 400 "The answer for question … must be a whole number from 1 to 5, written without leading zeros or a decimal point." The same goes for[4.0];["4"]and[4]are accepted.SubmissionServiceTestcovers the rejected forms and the accepted ones at both bounds,submit-form.spec.tschecks that a draft with"05"is sent as"5", and all of it was checked against a Nextcloud 35 test instance.🤖 AI (if applicable)